<template>
    <el-container>
        <el-aside width="70%">
            <el-container>
                <el-main>
                    <gridPage ref="grid" :config="gridConfig" :before-search="beforeSearch" @celick="celick"/>
                </el-main>
            </el-container>
        </el-aside>
        <el-container>
            <el-header class="height_auto pdbt" style="text-align:center">模块信息</el-header>
            <el-main>
                <form-panel
                    ref="myForm"
                    templet="DIC_MOUDLE"
                    form-type="edit"
                    form-cols="1"
                    :beforesave="mangerform_beforesave"
                    :buttons="mangerformbuttons"
                    :data="mangerformdata"
                    :remote="remotFunc"
                    :aftersave="managerform_aftersave"
                />
            </el-main>           
        </el-container>
    </el-container>
</template>

<script>
import gridPage from '@/components/TablePage/gridPage2';
import formpanel from '@/components/formpanel';
import request from '@/utils/requestutil';
export default {
  props:{
    // 接收，属性
  },
  components: {
    // 组件化开发
    gridPage,
    'form-panel':formpanel,
  },
  data() {
    // 全局变量
    return {
        mangerformdata: {
          code: '',
          name: '',
          memo: '',
          flag: '',
          isDefault: 'Y',
        },
        // remotFunc: {
        //   YwList: this.YwList
        // },
        mangerformbuttons: ['save'],//保存按钮
        gridConfig: {
            settings: {
            height: '100%',
            maxHeight: '100%',
            // flag: 'SLTJ_TS_CONINFO_QUERY0',
            templet:'DIC_MOUDLE',
            queryTemplet:'DIC_MOUDLE',
            queryFormCols:'4'
            },
            odel: '',
            options: {
            // searchConfig: {
            //   remotFunc: {
            //     YwList: this.YwList
            //   }
            // },
            treeConfigKey: '',
            checkType: 'check', // check // no
            isEdit: false, // 是否行内编辑
            isIndex: true, // 是否有索引
            isSort: false, // 是否拖拽排序
            tableToolbar: {
                refresh: true,//刷新
                zoom: true,//放大框
                export:true,
                tools: [
                    {
                        code: 'exportWord_slot',
                        name: '导出',
                        // icon: 'fa fa-cloud-download',
                        // handler: this.export
                    }
                ],
                buttons: [
                    {
                        code: "btnDemo1",
                        name: "新建",
                        handler: this.addNew
                    },
                    {
                        code: "btnDemo2",
                        name: "删除",
                        handler: this.deleteRow
                    },
                    {
                        code: "btnDemo2",
                        name: "发布",
                        handler: this.pubRwData
                    },
                ]
              }
            }
        },

    }
  },
  created() {
    // 初始化渲染
  },
  mounted(){
    // 组件渲染
  },
  watch: {
    // 监听事件
  },
  methods: {
    // 函数，点击事件
    beforeSearch(data, grid) {
      // const ttId = "`" + data.F_ttId + "`"
      // grid.queryParams = { F_ttSts: '[C,A]', F_ttId: `01` }
      grid.queryParams = { code: data.code }
      return data
    },
    //新增
    addNew(){
      this.mangerformdata = {
          code: '',
          name: '',
          memo: '',
          flag: '',
          isDefault: 'Y',
      }
      this.$refs.myForm.disabled('code', false)
      this.myOperator = 'NEW'
    },
    // 编辑
    celick(val) {
      debugger
      window.grid = this.$refs.grid
      this.$refs.myForm.disabled('code', true)
      // this.$refs.myForm.disableItem('isdefault', 'Y')
      this.mangerformdata = val
      this.myOperator = 'UPDATE'
      this.$refs.myForm.setData = {}
    },
    //删除
    deleteRow() {
      const t = this
      const selectrows = t.$refs.grid.getSelected()
      debugger
      if (selectrows.length === 0) {
        t.$message({
          message: '请至少选择一条数据',
          type: 'warning'
        })
        return
      } else {
        const xObj = []
        for (let i = 0; i < selectrows.length; i++) {
          xObj.push(selectrows[i].bzcode)
        }
        t.BZCODES = xObj.join(',')
      }
      debugger
      t.$confirm('确认删除？', '提示', {
        distinguishCancelAndClose: true,
        confirmButtonText: '确认',
        cancelButtonText: '取消'
      })
        .then(() => {
          request({
            url: 'Testdelete',
            data: {
              BZCODE: t.BZCODES,
              MODLE: 'SLTJ_T_BUSINESS_EDIT',
              PK: 'BZCODE'
            },
            method: 'post'
          }).then((data) => {
            debugger
            if (data.result === 'SUCCESS') {
              t.$refs.grid.refresh()
              t.$message({
                message: '删除成功',
                type: 'success'
              })
            } else {
              t.$message({
                message: '删除失败，请重新选择删除',
                type: 'warning'
              })
            }
          })
        })
        .catch(action => {
          t.$message({
            type: 'info',
            message: action === 'cancel'
              ? '已取消'
              : '已取消'
          })
        })
    },
    //保存之前
    myForm_beforesave() {
      this.$refs.myForm.setCommand(this.myOperator)
    },
    //保存之后
    managerform_aftersave(res, data) {
      if (res.result === 'SUCCESS') {
        this.$refs.grid.refresh()
      }
    },
    //锁住拖动排序
    lockMoveCheckedChange(obj) {
      this.$refs.grid.setLockColumnable(!obj.checked);
      let grid = this.$refs.grid;
      grid.setLockColumnable(!obj.checked);
      grid.resetSearch();
      setTimeout(() => {
        grid.search();
      }, 1);
    },

  }
};
</script>
<style scoped>
</style>
